package org.idea.spring.aop.version2.proxy;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import org.springframework.stereotype.Component;

/**
 * @Author linhao
 * @Date created in 10:55 上午 2021/5/15
 */
@Component
public class CglibProxyImpl {

    /**
     * 创建代理对象
     *
     * @param clazz
     * @return
     */
    public Object createProxy(Class clazz, MethodInterceptor methodInterceptor){
        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(methodInterceptor);
        enhancer.setSuperclass(clazz);
        return enhancer.create();
    }
}
